package fina2.dcs.returns;

import java.io.File;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;

@SuppressWarnings("serial")
public class ReturnReviewServlet extends HttpServlet {

	private Log log = Logging.getLog(getClass());

	public void service(HttpServletRequest request, HttpServletResponse response) {
		String fileName = null;
		try {
//			int returnId = Integer.parseInt(request.getParameter("id"));
//
//			ReturnSheet rs = new ReturnSheet(true, LanguageSession.langId.intValue());
//
//			TableRowImpl tri = new TableRowImpl(new ReturnPK(73), 8);
//			tri.setBlank(false);
//			tri.setDefaultCol(0);
//			tri.setValue(0, "MFB.1000");
//			tri.setValue(1, "01/02/2010");
//			tri.setValue(2, "28/02/2010");
//			tri.setValue(3, "Statement of Profit and Loss Account");
//			tri.setValue(4, "50016");
//			tri.setValue(5, "ORI");
//			tri.setValue(6, "AMENDED");
//			tri.setValue(7, "MFB.FINREP ");
//
//			rs.initReturnSheet(new ReturnPK(73), tri, "Arial", 11);
//
//			OutputStream outStream = response.getOutputStream();
//
//			fileName = OOSheet.calcUrl.replace("file:///", "").replace("ods", "pdf").replace("%20", " ");
//			File f = new File(fileName);
//
//			response.setContentType("application/pdf");
//
//			response.setContentLength((int) f.length());
//			response.setHeader("Content-Disposition", "inline; filename=\"reviewed.pdf\"");
//			response.setHeader("Cache-Control", "no-cache");
//
//			byte[] buf = new byte[8192];
//			FileInputStream inStream = new FileInputStream(f);
//			int sizeRead = 0;
//			while ((sizeRead = inStream.read(buf, 0, buf.length)) > 0) {
//				outStream.write(buf, 0, sizeRead);
//			}
//			inStream.close();
//			outStream.close();
		}

		catch (Exception ex) {
			log.error(ex.getMessage(), ex);
		} finally {
			File f = new File(fileName);
			if (f.exists())
				f.delete();
			f = new File(fileName.replace("pdf", "ods"));
			if (f.exists())
				f.delete();
		}
	}

}
